﻿using System.Collections.Generic; 
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;

namespace XFGameFramework.TweenSystem
{

    public enum AnimationValueType 
    {
        Float,
        Vector2,
        Vector3,
        Quaternion,
        Color,
        String
    }

    [CustomEditor(typeof(TweenAnimation))]
    public class TweenAnimationInspector : Editor
    { 

        private List<SerializedProperty> properties = null;

        private SerializedProperty mScript = null;
         
           
        private SerializedProperty onPlay; 

        private SerializedProperty onPause;

        [SerializeField]
        private bool eventFoldout = false;
         
        private GUIContent eventFoldoutContent;


        private SerializedProperty sequence;

        private SerializedProperty sequenceLoopMode;

        private GUIContent animationLabel;

        private void OnEnable()
        { 

            properties = serializedObject.GetAllSerializedProperty();
            mScript = serializedObject.FindProperty("m_Script");
         
            onPlay = serializedObject.FindProperty("onPlay");
            onPause = serializedObject.FindProperty("onPause");

            sequence = serializedObject.FindProperty("sequence");

            sequenceLoopMode = serializedObject.FindProperty("sequenceLoopMode");
        }


        public override void OnInspectorGUI()
        {
            TweenAnimation tweenAnimation = target as TweenAnimation;

            if (tweenAnimation == null) return;

            serializedObject.Update();

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.PropertyField(mScript);
            EditorGUI.EndDisabledGroup();

            foreach (var property in properties)
            { 

                if (property.name == "onPlay" || property.name == "onPause") continue;

                if (property.name == "sequenceLoopMode" || property.name == "sequenceLoopCount" || property.name == "onSequenceCompleted") 
                {
                    if (sequence.boolValue)
                    {

                        if (property.name == "sequenceLoopCount")
                        {
                            if ((LoopMode)sequenceLoopMode.intValue == LoopMode.Once)
                                continue;
                            
                        }

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(15); 
                        EditorGUILayout.PropertyField(property);
                        
                        EditorGUILayout.EndHorizontal();
                    }

                    continue;
                }
                if (property.name == "animationDatas")
                {
                    if (animationLabel == null)
                        animationLabel = new GUIContent();

                    animationLabel.text = "动画数据";

                    EditorGUILayout.PropertyField(property,animationLabel);
                }
                else {
                    EditorGUILayout.PropertyField(property);
                }
            }

            if (eventFoldoutContent == null)
                eventFoldoutContent = new GUIContent();

            eventFoldoutContent.text = "事件";

            eventFoldout = EditorGUILayout.Foldout(eventFoldout, eventFoldoutContent);
             
            if (eventFoldout)
            {
                EditorGUILayout.PropertyField(onPlay);
                EditorGUILayout.PropertyField(onPause);
            }

            serializedObject.ApplyModifiedProperties();
        }

          
    }   

}
